package com.linpq.road.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdPavementDamage;
import com.linpq.road.service.RdPavementDamageService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 路面破损Controller
 *
 * @author linpq
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/pavement_damage")
public class RdPavementDamageController extends BaseController {
    private String prefix = "road/pavement_damage";

    @Autowired
    private RdPavementDamageService rdPavementDamageService;

    @RequiresPermissions("road:pavement_damage:view")
    @GetMapping()
    public String pavement_damage() {
        return prefix + "/pavement_damage";
    }

    /**
     * 查询路面破损列表
     */
    @RequiresPermissions("road:pavement_damage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdPavementDamage rdPavementDamage) {
        startPage();
        List<RdPavementDamage> list = rdPavementDamageService.selectRdPavementDamageList(rdPavementDamage);
        return getDataTable(list);
    }

    /**
     * 导出路面破损列表
     */
    @RequiresPermissions("road:pavement_damage:export")
    @Log(title = "路面破损", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdPavementDamage rdPavementDamage) {
        List<RdPavementDamage> list = rdPavementDamageService.selectRdPavementDamageList(rdPavementDamage);
        ExcelUtil<RdPavementDamage> util = new ExcelUtil<RdPavementDamage>(RdPavementDamage. class);
        return util.exportExcel(list, "pavement_damage");
    }

    /**
     * 新增路面破损
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存路面破损
     */
    @RequiresPermissions("road:pavement_damage:add")
    @Log(title = "路面破损", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdPavementDamage rdPavementDamage) {
        return toAjax(rdPavementDamageService.insertRdPavementDamage(rdPavementDamage));
    }

    /**
     * 修改路面破损
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdPavementDamage rdPavementDamage =rdPavementDamageService.selectRdPavementDamageById(id);
        mmap.put("rdPavementDamage", rdPavementDamage);
        return prefix + "/edit";
    }

    /**
     * 修改保存路面破损
     */
    @RequiresPermissions("road:pavement_damage:edit")
    @Log(title = "路面破损", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdPavementDamage rdPavementDamage) {
        return toAjax(rdPavementDamageService.updateRdPavementDamage(rdPavementDamage));
    }

    /**
     * 删除路面破损
     */
    @RequiresPermissions("road:pavement_damage:remove")
    @Log(title = "路面破损", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdPavementDamageService.deleteRdPavementDamageByIds(ids));
    }
}
